import django_filters
from rest_framework import filters
from django_filters.rest_framework import DjangoFilterBackend

from orders.models import *


class OrderInfoFilter(django_filters.rest_framework.FilterSet):
    '''订单过滤'''

    create_time_begin = django_filters.DateTimeFilter(field_name="create_time", lookup_expr='gte')
    create_time_end = django_filters.DateTimeFilter(field_name="create_time", lookup_expr='lte')
    payment_time_begin = django_filters.DateTimeFilter(field_name="payment_time", lookup_expr='gte')
    payment_time_end = django_filters.DateTimeFilter(field_name="payment_time", lookup_expr='lte')
    use_time_begin = django_filters.DateTimeFilter(field_name="use_time", lookup_expr='gte')
    use_time_end = django_filters.DateTimeFilter(field_name="use_time", lookup_expr='lte')
    state = django_filters.BaseInFilter(field_name='state', lookup_expr='in')
    total_price_min = django_filters.NumberFilter(field_name="total_price", lookup_expr='gte')
    total_price_max = django_filters.NumberFilter(field_name="total_price", lookup_expr='lte')
    customeruser_id = django_filters.BaseInFilter(field_name='customer_user_id', lookup_expr='in')
    merchant_id = django_filters.BaseInFilter(field_name='merchant_id', lookup_expr='in')
    bill_id = django_filters.BaseInFilter(field_name='bill_id', lookup_expr='in')
    goods_id = django_filters.BaseInFilter(field_name='ordergoods__goods_id', lookup_expr='in')
    order_species = django_filters.BaseInFilter(field_name='order_species', lookup_expr='in')

    class Meta:
        model = OrderInfo
        fields = ('create_time_begin', 'create_time_end', 'state', 'total_price_min', 'total_price_max', 'customeruser_id', 'merchant_id', 'bill_id', 'goods_id',
                  'use_time_begin', 'use_time_end', 'order_species', 'payment_time_begin', 'payment_time_end')


class OrderInfoGROUPFilter(django_filters.rest_framework.FilterSet):

    group_status = django_filters.BaseInFilter(field_name='group_status', lookup_expr='in')
    create_time_begin = django_filters.DateTimeFilter(field_name="create_time__date", lookup_expr='gte')
    create_time_end = django_filters.DateTimeFilter(field_name="create_time__date", lookup_expr='lte')
    expired_time_begin = django_filters.DateTimeFilter(field_name="expired_time__date", lookup_expr='gte')
    expired_time_end = django_filters.DateTimeFilter(field_name="expired_time__date", lookup_expr='lte')
    group_order_num_max = django_filters.NumberFilter(field_name="group_order_num", lookup_expr='lte')
    group_order_num_min = django_filters.NumberFilter(field_name="group_order_num", lookup_expr='gte')

    class Meta:
        model = OrderInfoGROUP
        fields = ('group_status', 'create_time_begin', 'create_time_begin', 'expired_time_begin', 'expired_time_end',
                  'group_order_num_max', 'group_order_num_min')


class OrderSchengleFilter(django_filters.rest_framework.FilterSet):

    order_state = django_filters.BaseInFilter(field_name='order_state', lookup_expr='in')

    class Meta:
        model = OrderSchengle
        fields = ('order_state',)


class OrderAdvanceFilter(django_filters.rest_framework.FilterSet):

    order_id = django_filters.BaseInFilter(field_name='order_id', lookup_expr='in')

    class Meta:
        model = OrderAdvance
        fields = ('order_id', )


class ExpressFilter(django_filters.rest_framework.FilterSet):

    deliverystatus = django_filters.BaseInFilter(field_name='deliverystatus', lookup_expr='in')
    create_time_begin = django_filters.DateTimeFilter(field_name="create_time__date", lookup_expr='gte')
    create_time_end = django_filters.DateTimeFilter(field_name="create_time__date", lookup_expr='lte')
    sign_time_begin = django_filters.DateTimeFilter(field_name="sign_time__date", lookup_expr='gte')
    sign_time_end = django_filters.DateTimeFilter(field_name="sign_time__date", lookup_expr='lte')

    class Meta:
        model = Express
        fields = ('deliverystatus', 'create_time_begin', 'create_time_end', 'sign_time_begin', 'sign_time_end')